#pragma once
#include<iostream>
#include<fstream>
#include<sstream>
#include<ctime>
#include<sys/stat.h>
namespace yd
{
    class date
    {
        public:
        static time_t now(){return time(nullptr);}
    };
    class file
    {
        public:
        static bool exists(const std::string&pathname)
        {
            struct stat st;
            return stat(pathname.c_str(),&st)==0;
        }
        static std::string path(const std::string&path)
        {
            if(path.empty())return ".";
            size_t pos=path.find_last_of("/\\");
            if(pos==std::string::npos)return ".";
            return path.substr(0,pos+1);
        }
        static void create_dir(const std::string &path)
        {
            if(path.empty())return;
            if(exists(path))return;
            int pos=0;int idx=0;
            while(idx<path.size())
            {
                pos=path.find_first_of("/\\",idx);
                if(pos==std::string::npos)
                {
                    mkdir(path.c_str(),0755);
                    return;
                }
                if(pos==idx){idx==pos+1;continue;}
                std::string sub_str=path.substr(0,pos);
                if(sub_str=="."||sub_str==".."){idx=pos+1;continue;}
                if(exists(sub_str)){idx=pos+1;continue;}
                mkdir(sub_str.c_str(),0755);
                idx=pos+1;
            }
        }

    };
}